var logoutBtn = document.getElementById('logoutBtn');
var content = document.querySelector('.content');
var container = document.querySelector('.container');

content.addEventListener('mouseenter', function() {
  content.style.transition = 'background-color 0.3s';
  content.style.backgroundColor = 'rgba(100,100,100,0.5)'; // 将透明度更改为 0.5，使背景色加深
});

content.addEventListener('mouseleave', function() {
  content.style.transition = 'background-color 0.3s';
  content.style.backgroundColor = 'rgba(100,100,100,0.2)'; // 将透明度恢复为 0.2，使背景色变浅
});

// script.js

document.addEventListener("DOMContentLoaded", function() {

  const nameElement = document.querySelector('.info-text[name="name"]');
  const genderElement = document.querySelector('.info-text[name="gender"]');
  const levelElement = document.querySelector('.info-text[name="level"]');
  const phoneElement = document.querySelector('.info-text[name="phone"]');
  const emailElement = document.querySelector('.info-text[name="email"]');
  const majorElement = document.querySelector('.info-text[name="major"]');
  const classElement = document.querySelector('.info-text[name="class"]');

  const tmpName = document.querySelector('.welcome[name="name"]')

  $.ajax({
    url: '/management/stuservlet/stuMenu',
    method: 'POST',
    data: {
      username: nameElement.textContent
    },
    success: function(response) {
//      console.log(response['name']);
//      console.log(response[1]);
      console.log(response);
      console.log(response.data);
//      nameElement.textContent = response['name'];
//      genderElement.textContent = response['gender'];
//      birthdateElement.textContent = response['birthdate'];
//      phoneElement.textContent = response['phone'];
//      emailElement.textContent = response['email'];
//      majorElement.textContent = response['major'];
//      classElement.textContent = response['class'];
      var data = response.data;
      // 将数据数组赋值给相应的元素
      tmpName.textContent = data[0];
      nameElement.textContent = data[0];
      genderElement.textContent = data[1];
      levelElement.textContent = data[4];
      phoneElement.textContent = data[5];
      emailElement.textContent = data[3];
      majorElement.textContent = data[2];
      classElement.textContent = data[6];
    }
  });
  var links = document.querySelectorAll('.sidebar ul li a');

  for (var i = 0; i < links.length; i++) {
    links[i].addEventListener('mouseenter', function() {
      this.style.transition = '0.2s';
      this.style.backgroundColor = '#679';
      this.style.borderRadius = '10px'; // 设置边缘的圆角半径为10px
    });

    links[i].addEventListener('mouseleave', function() {
      this.style.transition = '0.2s';
      this.style.backgroundColor = '';
      this.style.borderRadius = '10px'; // 鼠标移出时恢复原始边缘
    });
  }

  // 更新页面元素的内容
//  nameElement.textContent = data.name;
//  genderElement.textContent = data.gender;
//  birthdateElement.textContent = data.birthdate;
//  phoneElement.textContent = data.phone;
//  emailElement.textContent = data.email;
//  majorElement.textContent = data.major;
//  classElement.textContent = data.class;
});

logoutBtn.addEventListener('click', function() {
  var confirmLogout = confirm("确定要退出吗？");

  if (confirmLogout) {
    // 用户点击了确认按钮
    // 编写退出登录的操作
    window.location.href = "welcome.html";
  } else {
    // 用户点击了取消按钮
    // 可以选择执行其他操作或不进行任何操作
  }
});

if (document.readyState === 'complete') {
  // 页面已完全加载 在这里隐藏 loading
}